let prizesApp = new Vue({
  el: '#prizesApp',
  data: {
    loading: 1,
    selectedOption: '', // 初始值为空
    currentDate: '',
    load:true,
    statusCreate: [], // 创建时间
    prizes: [], // 视频列表主页
    next: [],  // 下一页
    checkbox: [],  // 是否显示
    isVisible: null,  // 是否显示删除内容
    isMessage: false, // 是否显示消息
    message: '',  // 消息内容 // 消息内容
  
  },
  methods: {
    prizesApp : function () {
      console.log("prizesApp")
      $.ajax({
        url: '/web/prizes/all',
        method: 'GET',
        success: function (e) {

          console.log("prizes{}", e);
          prizesApp.prizes = e;
          prizesApp.load = false;
          prizesApp.loading = 0;

        }
      })
    },

    onUpdate:function (res){
      if (this.isVisible === null || this.isVisible !== res.id){
        prizesApp.isVisible = res.id;
        return;
      }
      prizesApp.isVisible = res.id;
      console.log("update",res)
      $.ajax({
        url: '/web/prizes/update',
        method: 'GET',
                data: {
                    id: res.id,
                    text: res.text,
                    src: res.src,
                    ranges: res.ranges,
                    time: res.time
                },
              success: function (res) {
                console.log("res{}", res);
                if (res.code == OK) {
                  prizesApp.onmessage("修改成功");
                  console.log("成功修改");
                  prizesApp.isVisible = null;
                }
              },
              error: function (e) {
                console.log("修改失败");
                prizesApp.onmessage("修改失败");
              }
            })

    },


    onmessage: function (message) {
      prizesApp.message = message;
      prizesApp.isMessage = true;
      setTimeout(function () {
        prizesApp.isMessage = false;
      }, 2000);
    },

    // 获取当前时间
    formatDate(date) {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      const hours = String(date.getHours()).padStart(2, '0');
      const minutes = String(date.getMinutes()).padStart(2, '0');
      const seconds = String(date.getSeconds()).padStart(2, '0');
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    updateDate() {
      const now = new Date();
      this.currentDate = this.formatDate(now);
    }

  }, created: function () {
    // 初始化日期
    this.updateDate();
    // 每秒更新时间
    this.interval = setInterval(this.updateDate, 1000);
    this.prizesApp();
  },
  beforeDestroy() {
    // 清除定时器
    clearInterval(this.interval);
  }
})